package com.demo.gateway.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.demo.gateway.pojo.ScheduleJobDO;

/**
 * @author: demo
 * @date: 2020年7月3日
 * @Document :定时操作类
 */
@Mapper
public interface JobMapper {
    
	 /**
	  * 查询启动的定时任务 
	  * @return
	  */
	@Select("select * from gateway_schedule_job where delete_flag=0 and  status=1")
	 public  List<ScheduleJobDO>  queryStartJobs();
	
	
	/**
	 * 删除定时任务
	 * @param id
	 * @return
	 */
	@Update("update  gateway_schedule_job  set delete_flag=1  where id=#{id}")
	public  int  deleteScheduleJob(int id);
	
	/**
	 * 增加定时任务
	 * @param job
	 * @return 
	 */
	@Insert({"INSERT INTO gateway_schedule_job( job_name, cron_expression, bean_name, method_name, status, delete_flag, created_time, updated_time)  ",
			"VALUES (#{jobName},#{cronExpression},#{beanName},#{methodName},1,0,#{createTime},#{createTime})"})
	public  int  addScheduleJob(ScheduleJobDO job);
	
	/**
	 * 暂停定时任务
	 * @param id
	 * @return
	 */
	@Update("update  gateway_schedule_job  set status=2  where id=#{id}")
	public  int  pauseScheduleJob(int id);
	
	
	/**
	 * 更新定时任务
	 * @param job
	 * @return
	 */
	@Update({"UPDATE gateway_schedule_job  SET job_name =#{jobName}, cron_expression = #{cronExpression}, ",
		"bean_name = #{beanName}, method_name =#{methodName}, status = #{status}, delete_flag = #{deleteFlag}, ",
		"updated_time =#{updatedName}  WHERE id = #{id}"})
	public  int updateScheduleJob(ScheduleJobDO job);
}
